package com.ruoyi.boat.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.boat.domain.TBlock;
import com.ruoyi.boat.service.ITBlockService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 障碍物Controller
 * 
 * @author ruoyi
 * @date 2024-07-15
 */
@Controller
@RequestMapping("/boat/block")
public class TBlockController extends BaseController
{
    private String prefix = "boat/block";

    @Autowired
    private ITBlockService tBlockService;

    @RequiresPermissions("boat:block:view")
    @GetMapping()
    public String block()
    {
        return prefix + "/block";
    }

    /**
     * 查询障碍物列表
     */
    @RequiresPermissions("boat:block:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TBlock tBlock)
    {
        startPage();
        List<TBlock> list = tBlockService.selectTBlockList(tBlock);
        return getDataTable(list);
    }

    /**
     * 导出障碍物列表
     */
    @RequiresPermissions("boat:block:export")
    @Log(title = "障碍物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBlock tBlock)
    {
        List<TBlock> list = tBlockService.selectTBlockList(tBlock);
        ExcelUtil<TBlock> util = new ExcelUtil<TBlock>(TBlock.class);
        return util.exportExcel(list, "障碍物数据");
    }

    /**
     * 新增障碍物
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存障碍物
     */
    @RequiresPermissions("boat:block:add")
    @Log(title = "障碍物", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBlock tBlock)
    {
        return toAjax(tBlockService.insertTBlock(tBlock));
    }

    /**
     * 修改障碍物
     */
    @RequiresPermissions("boat:block:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TBlock tBlock = tBlockService.selectTBlockById(id);
        mmap.put("tBlock", tBlock);
        return prefix + "/edit";
    }

    /**
     * 修改保存障碍物
     */
    @RequiresPermissions("boat:block:edit")
    @Log(title = "障碍物", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBlock tBlock)
    {
        return toAjax(tBlockService.updateTBlock(tBlock));
    }

    /**
     * 删除障碍物
     */
    @RequiresPermissions("boat:block:remove")
    @Log(title = "障碍物", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tBlockService.deleteTBlockByIds(ids));
    }
}
